package org.qnit.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository("mysqlQuery")
public class MysqlQuery {

    private Logger logger = LoggerFactory.getLogger(MysqlQuery.class);

    @Autowired
    @Qualifier("mysqlJdbcTemplate")
    private JdbcTemplate mysqlJdbcTemplate;

    public Map<String, Object> getUserByMilvus(String milvusKey) {
        try {
            String sql = String.format("select * from qnit.user_milvus_mapping where milvus_key=%s", milvusKey);
            Map<String, Object> maps = mysqlJdbcTemplate.queryForMap(sql);
            return maps;
        } catch (DataAccessException e) {
            logger.error(e.getMessage());
            return null;
        }
    }

}
